package com.itany.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.pojo.Permission;
import com.itany.mapper.PermissionMapper;
import com.itany.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author：sl
 * Date：2019-09-25 上午10:48
 * Description：<描述>
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    PermissionMapper permissionMapper;

    public PageInfo<Permission> findAllPermission(Integer page, Integer rows) {
        PageHelper.startPage(page, rows);
        List<Permission> permissions = permissionMapper.selectAll();
        PageInfo<Permission> info = new PageInfo<Permission>(permissions);

        if (info.getList().size() != 0) {
            for (Permission p : info.getList()) {
                Permission parentPermission = permissionMapper.selectById(p.getParentId());
                p.setParentPermission(parentPermission);
            }
        }
        return info;
    }




    public List<Permission> findModule() {

        List<Permission> list = permissionMapper.selectModule();

        return list;
    }


    public void modifyById(Permission permission) {

        permissionMapper.updateById(permission);

    }
}
